//
//  MBChatNavView.m
//  Meboo
//
//  Created by kyo on 2023/10/16.
//

#import "MBChatNavView.h"
@interface MBChatNavView ()
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIButton *leftBtn;
@end

@implementation MBChatNavView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Action

- (void)backAction {
    [self.currentViewController.navigationController popViewControllerAnimated:YES];;
}

#pragma mark - UI
- (void)setupUI {
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(self.mas_top).offset(StatusBarAndNavigationBarHeight-MBHeightScale(8));
    }];
    
    [self addSubview:self.leftBtn];
    [self.leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(20));
        make.centerY.equalTo(self.titleLab);
        make.width.height.mas_equalTo(MBHeightScale(20));
    }];
}

#pragma mark - Setter && Getter

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textAlignment = NSTextAlignmentCenter;
        _titleLab.font = PDSemiBoldScale(20);
        _titleLab.textColor = HEXS(@"333333");
        _titleLab.text = @"Chat";
    }
    return _titleLab;
}

- (UIButton *)leftBtn {
    if (!_leftBtn) {
        _leftBtn = [[UIButton alloc] init];
        [_leftBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_leftBtn setImage:ImageWithName(@"back_arrow_black") forState:0];
        [_leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _leftBtn;
}

@end
